/*package net.mysoft.budgetsoft.system.dao.impl;
 
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import net.mysoft.budgetsoft.system.dao.FlowTaskNodeDao;
import net.mysoft.budgetsoft.system.domain.TFlowTaskNode;
import net.mysoft.budgetsoft.system.pagemodel.FlowTaskNode;
import net.mysoft.framework.base.BaseDaoImpl;
import net.mysoft.framework.model.SessionInfo;
import net.mysoft.framework.util.ResourceUtil;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Repository;
*//**   
 *  
 * @author dagongPGP v1.0 
 * @link <a href=http://www.dagongsoft.net>北京大公信软科技有限公司</a> 
 *  
 * @version $Revision: 1.00  $Date: 2013-07-08 17:26:33 
 *//*  
@Repository("flowTaskNodeDaoImpl")
public class FlowTaskNodeDaoImpl extends BaseDaoImpl implements FlowTaskNodeDao{  
	
	@Resource
	private WeiTuoWHDao weiTuoWHDao;
	
	public WeiTuoWHDao getWeiTuoWHDao() {
		return weiTuoWHDao;
	}

	public void setWeiTuoWHDao(WeiTuoWHDao weiTuoWHDao) {
		this.weiTuoWHDao = weiTuoWHDao;
	}

	@Override
	public List<TFlowTaskNode> find(FlowTaskNode flowTaskNode){
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params,null,null,null,null);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = new ArrayList();
		if(flowTaskNode.getPage()==0&&flowTaskNode.getRows()==0){
			toList = this.find(hql,params);
		}else{
			toList = this.find(hql,params,flowTaskNode.getPage(),flowTaskNode.getRows());
		}
		return toList;
	}
	
	@Override
	public List<TFlowTaskNode> find(FlowTaskNode flowTaskNode,String renWuHQL,List renWuHQLParams,String xiangMuHQL,List xiangMuHQLParams){
		String hql = "from TFlowTaskNode tFlowTaskNode where 1=1 ";
		List params = new ArrayList();
		hql = addWhere(flowTaskNode, hql, params,renWuHQL,renWuHQLParams,xiangMuHQL,xiangMuHQLParams);
		hql = addOrder(flowTaskNode, hql);
		List<TFlowTaskNode> toList = this.find(hql, params);
		return toList;
	}
	
	private String addWhere(FlowTaskNode flowTaskNode, String hql, List<Object> params,String renWuHQL,List renWuHQLParams,String xiangMuHQL,List xiangMuHQLParams) {
		if(flowTaskNode.getXiangMuJBXXBH()!=null&&!"".equals(flowTaskNode.getXiangMuJBXXBH())){
			hql+=" and tFlowTaskNode.xiangMuJBXXBH = ?";
			params.add(flowTaskNode.getXiangMuJBXXBH());
		}
		if(flowTaskNode.getRenWuJBXXBH()!=null&&!"".equals(flowTaskNode.getRenWuJBXXBH())){
			hql+=" and tFlowTaskNode.renWuJBXXBH = ?";
			params.add(flowTaskNode.getRenWuJBXXBH());
		}
		if(flowTaskNode.getFtn_Status()!=null){
			hql+=" and tFlowTaskNode.ftn_Status = ?";
			params.add(flowTaskNode.getFtn_Status());
		}
		if(flowTaskNode.getFtn_UserCode()!=null){
			SessionInfo sessionInfo = (SessionInfo) ServletActionContext.getRequest().getSession().getAttribute(ResourceUtil.getSessionInfoName());
			if(sessionInfo.getRoleIds().indexOf(ResourceUtil.ADMIN_ROLE_ID)<0&&!sessionInfo.getUserId().equals("YongHu2013102900001")){
				hql+=" and tFlowTaskNode.ftn_UserCode in ( ";
				String userCodes = flowTaskNode.getFtn_UserCode();
				//System.out.println("+++添加前的userCodes:"+userCodes);
				//userCodes = addWTRUserCodes(userCodes,new Date());
				//System.out.println("+++添加后的userCodes:"+userCodes);
				boolean first = true;
				for(String userCode :userCodes.split(",") ) {
					if(first) {
						hql += "?";
						params.add(userCode);
						first = false;
					}else {
						hql += ",?";
						params.add(userCode);
					}
				}
				hql += ") ";
			}
		}
		if(flowTaskNode.getFtn_Class()!=null){
			if(flowTaskNode.getFtn_Class().indexOf(",")>0){
				String[] classArr = flowTaskNode.getFtn_Class().split(",");
				hql+=" and tFlowTaskNode.flowNodeClass.fnc_ID in(";
				int x=0;
				for(String cla:classArr){
					if(x>0){
						hql+=",";
					}
					hql+="?";
					params.add(cla);
					x++;
				}
				hql+=")";
			}else{
				hql+=" and tFlowTaskNode.flowNodeClass.fnc_ID = ?";
				params.add(flowTaskNode.getFtn_Class());
			}
		}
		if (flowTaskNode.getDatetimeEnd() != null
				&& !flowTaskNode.getDatetimeEnd().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleBeginTime <= ? ";
			params.add(flowTaskNode.getDatetimeEnd());
		}
		if (flowTaskNode.getDatetimeStart() != null
				&& !flowTaskNode.getDatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleBeginTime >= ? ";
			params.add(flowTaskNode.getDatetimeStart());
		}
		if (flowTaskNode.getEnddatetimeEnd() != null
				&& !flowTaskNode.getEnddatetimeEnd().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime <= ? ";
			params.add(flowTaskNode.getEnddatetimeEnd());
		}
		if (flowTaskNode.getEnddatetimeStart() != null
				&& !flowTaskNode.getEnddatetimeStart().equals("")) {
			hql += " and tFlowTaskNode.ftn_HandleEndTime >= ? ";
			params.add(flowTaskNode.getEnddatetimeStart());
		}
	
		if(flowTaskNode.getYeWuZLBH() != null&&!"".equals(flowTaskNode.getYeWuZLBH())) {
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.yeWuZL.bianHao=?) " +
					"or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.yeWuZLWH.bianHao=?) ) ";
			params.add(flowTaskNode.getYeWuZLBH());
			params.add(flowTaskNode.getYeWuZLBH());
		}
		if(flowTaskNode.getQiYeMC() != null&&!"".equals(flowTaskNode.getQiYeMC())) {
			hql += "and (tFlowTaskNode.renWuJBXXBH in(select tr.bianHao from TRenWuJBXX tr where tr.qiYeMC like ?) " +
			"or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.shouPingZT.qiYeZWMC like ? or tx.shouPingZT.qiYeYWMC like ?) ) ";
			params.add("%"+flowTaskNode.getQiYeMC()+"%");
			params.add("%"+flowTaskNode.getQiYeMC()+"%");
			params.add("%"+flowTaskNode.getQiYeMC()+"%");
		}
		if(renWuHQL!=null&&!"".equals(renWuHQL)&&renWuHQLParams!=null&&renWuHQLParams.size()!=0){
			hql+=" and tFlowTaskNode.renWuJBXXBH in("+renWuHQL+")";
			params.addAll(renWuHQLParams);
		}
		if(xiangMuHQL!=null&&!"".equals(xiangMuHQL)&&xiangMuHQLParams!=null&&xiangMuHQLParams.size()!=0){
			hql+=" and tFlowTaskNode.xiangMuJBXXBH in("+xiangMuHQL+")";
			params.addAll(xiangMuHQLParams);
		}
		if(flowTaskNode.getXiangMuZT()!=null) {
			hql+=" and (tFlowTaskNode.xiangMuJBXXBH is null or tFlowTaskNode.xiangMuJBXXBH in(select tx.xiangMuBH from TXiangMuJBXX tx where tx.xiangMuZT=?)) ) ";
			params.add(flowTaskNode.getXiangMuZT());
		}
		if(flowTaskNode.getDatagridType()!=null&&flowTaskNode.getDatagridType().equals("xiangMuLCJK")) {
			hql += "  and tFlowTaskNode.ftn_ID in (select max(tt.ftn_ID) from TFlowTaskNode tt where tt.ftn_Status=1 group by tt.flowNode.fln_ID) ";
		}
		if(flowTaskNode.getLiuChengJD()!=null&&!"".equals(flowTaskNode.getLiuChengJD())&&!"310".equals(flowTaskNode.getLiuChengJD())){
			hql += " and tFlowTaskNode.ftn_Name_cn = ? ";
			params.add(flowTaskNode.getLiuChengJD());
		}
		if(flowTaskNode.getFtn_XiangMuJD()!=null&&flowTaskNode.getFtn_XiangMuJD()!=310) {
			hql += " and tFlowTaskNode.ftn_XiangMuJD = ? ";
			params.add(flowTaskNode.getFtn_XiangMuJD());
		}
		if(flowTaskNode.getFtn_State()!=null&&!"".equals(flowTaskNode.getFtn_State())) {
			hql += " and tFlowTaskNode.ftn_State = ? ";
			params.add(flowTaskNode.getFtn_State());
		}
		if(flowTaskNode.getXiangMuYCLX()!=null&&!"".equals(flowTaskNode.getXiangMuYCLX())) {
			hql += " and tFlowTaskNode.xiangMuYCLX like ?";
			params.add("%"+flowTaskNode.getXiangMuYCLX()+"%");
		}
		if(flowTaskNode.getFtn_Name_cn()!=null&&!"".equals(flowTaskNode.getFtn_Name_cn())) {
			hql += " and tFlowTaskNode.ftn_Name_cn=? ";
			params.add(flowTaskNode.getFtn_Name_cn());
		}
	
		return hql;
	}
	*//**
	 * 递归查询添加受托人的userCodes
	 * @param userCodeList
	 * @param userCodes
	 * @return
	 *//*
	//userCodes至少有一个
	private String addWTRUserCodes(String userCodes,Date date ) {
		for(String userCode : userCodes.split(",")) {
			List<TWeiTuoWH> weiTuoWHs = weiTuoWHDao.find("from TWeiTuoWH t where t.shouTuoR=? and ?>=t.kaiShiSJ and ?<=t.jieShuSJ ",new Object[]{userCode,date,date});
			if(weiTuoWHs==null||weiTuoWHs.size()==0) {
				continue;
			}else {
				String currentUserCodes = "";
				boolean first = true;
				for(TWeiTuoWH weiTuoWH : weiTuoWHs) {
					if(first) {
						currentUserCodes += weiTuoWH.getWeiTuoR();
						first  = false;
					}else {
						currentUserCodes += ","+weiTuoWH.getWeiTuoR();
					}
				}
				userCodes += ","+addWTRUserCodes(currentUserCodes,date);
			}
		}
		//System.out.println("添加添加");
		return userCodes;
	}
	
	
	
	private String addOrder(FlowTaskNode flowTaskNode, String hql) {
		if (flowTaskNode.getSort() != null) {
			hql += " order by ";
			String[] sortArr = flowTaskNode.getSort().split(",");
			String[] orderArr = flowTaskNode.getOrder().split(",");
			for(int i=0;i<sortArr.length;i++){
				if(i>0)hql+=",";
				hql +=  sortArr[i]+" " +orderArr[i];
			}
		}
		return hql;
		
		
	}

	@Override
	public TFlowTaskNode get(String ftn_id) {
		TFlowTaskNode ftn = (TFlowTaskNode)this.get(TFlowTaskNode.class,ftn_id);
		if(ftn==null) {
			TFlowTaskNode_His ftn_h = (TFlowTaskNode_His)this.get(TFlowTaskNode_His.class,ftn_id);
			if(ftn_h!=null) {
				ftn = new TFlowTaskNode();
				BeanUtils.copyProperties(ftn_h, ftn);
			}
		}
		return ftn;
	}
	*//**
	 * 利用反射机制，根据ftn的步骤名称，将流程表的时间和人员注入到业务表的对象中
	 * @param obj
	 * @param ftnId
	 *//*
	public void immitUserDateInfo(Object obj,String ftnIds) {
		if(!ftnIds.startsWith("DR")) {//只注入历史数据
			return;
		}
		ResourceBundle bundle = java.util.ResourceBundle.getBundle("dateinfoconfig");
		
		for(String ftnId : ftnIds.split(",")) {
			TFlowTaskNode ftn = this.get(ftnId);
			String xiangMuJBXXBH = ftn.getXiangMuJBXXBH();
			if(xiangMuJBXXBH!=null&&!"".equals(xiangMuJBXXBH)){
				TXiangMuJBXX txiangmu = (TXiangMuJBXX) this.get(TXiangMuJBXX.class, xiangMuJBXXBH);
				if(txiangmu!=null&&ftn.getFtn_XiangMuJD()!=null){
					txiangmu.setXiangMuJD(ftn.getFtn_XiangMuJD());
					this.update(txiangmu);
				}
			}
			System.out.println(ftn.getFtn_Name_cn()+"            wwwuuu");
			try{
				String[] infoStr = bundle.getString(ftn.getFtn_Name_cn()).split(",");
				String userIDColumn = infoStr[1];
				String dateColumn = infoStr[2];
				System.out.println(ftn.getFtn_Name_cn()+"            youuuu");
				if(!ftn.getFtn_Name_cn().equals("上会评审")) {
					immitUser(obj,userIDColumn,ftn.getFtn_HandleUserCode());
				}
				immitDate(obj,dateColumn,ftn.getFtn_HandleEndTime());
			}catch(MissingResourceException e) {
			}
		}
	}
	*//**
	 * 注入人员
	 * @param obj
	 * @param userIDColumn
	 * @param ftnUserCode
	 *//*
	private  void immitUser(Object obj, String userIDColumn,String ftnUserCode){
		//利用反射机制，判断domian实体类中需要的是String用户的编号还是TUser的对象
		Class objClass = obj.getClass();
		String methedName = "set"
            + userIDColumn.substring(0, 1).toUpperCase()
            + userIDColumn.substring(1);
		Method m;
		try {
			m = objClass.getMethod(methedName, TUser.class); //需要的是User对象
			TUser user = new TUser();
			user.setUserID(ftnUserCode);
			try {
				m.invoke(obj,new Object[]{user});
				System.out.println("    注入人员："+ftnUserCode);
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		} catch (SecurityException e) {
			throw new RuntimeException(e);
		} catch (NoSuchMethodException e) {
			try {  //需要的是userid字符串
				m = objClass.getMethod(methedName, String.class);
				m.invoke(obj, new Object[]{ftnUserCode});
				System.out.println("    注入人员："+ftnUserCode);
			} catch (Exception e1) {
				throw new RuntimeException(e1);
			} 
		
		}
	}
	*//**
	 * 注入时间
	 * @param obj
	 * @param userIDColumn
	 * @param ftnDate
	 *//*
	private void immitDate(Object obj, String dateColumn,Date ftnDate) {
		if(dateColumn.equals("0")) {
			return;
		}
		Class objClass  = obj.getClass();
		String methedName = "set"
            + dateColumn.substring(0, 1).toUpperCase()
            + dateColumn.substring(1);
		try {
			Method m =  objClass.getMethod(methedName,Date.class );
			m.invoke(obj, new Object[]{ftnDate});
		} catch (Exception e) {
			throw new RuntimeException(e);
		} 
	}
}  
*/